package com.test.burnincash.activity_fragment_burnin.fragment_burnin;

import android.annotation.SuppressLint;
import android.os.Bundle;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.test.burnincash.R;
import com.test.burnincash.activity_fragment_burnin.base_burnin.BaseLoanFragment_burnin;
import com.test.burnincash.bean_burnin.config_info_burnin.AppShowInfo_burnin;
import com.test.burnincash.bean_burnin.process_burnin.ProcessInfo_burnin;
import com.test.burnincash.bean_burnin.user_info_burnin.LoanApplyDetailInfo_burnin;
import com.test.burnincash.constant_burnin.Constant_burnin;
import com.test.burnincash.util_burnin.http_burnin.HttpManager_burnin;

public class LoanWaitFragment_burnin extends BaseLoanFragment_burnin {

    private TextView loanAmountTv;
    private TextView loanTermTv;

    private TextView accountNumTv;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_loan_wait_burnin, container, false);
        init(view);
        return view;
    }

    @SuppressLint("SetTextI18n")
    private void init(View view){

        ImageView imageIv = view.findViewById(R.id.fragment_loan_wait_iv_image);
        TextView titleTv = view.findViewById(R.id.fragment_loan_wait_tv_title);
        TextView textTv = view.findViewById(R.id.fragment_loan_wait_tv_text);
        loanAmountTv = view.findViewById(R.id.fragment_loan_wait_tv_loan_amount);
        loanTermTv = view.findViewById(R.id.fragment_loan_wait_tv_loan_term);
        View showAccountView = view.findViewById(R.id.fragment_loan_wait_view_show_account);
        TextView accountTextTv = view.findViewById(R.id.fragment_loan_wait_tv_show_account_text);
        TextView accountNameTv = view.findViewById(R.id.fragment_loan_wait_tv_show_account_name);
        accountNumTv = view.findViewById(R.id.fragment_loan_wait_tv_show_account_num);
        View tipsView = view.findViewById(R.id.fragment_loan_wait_view_tips);

        view.findViewById(R.id.fragment_loan_wait_layout_refresh_status).setOnClickListener(v -> HttpManager_burnin.getInstance().requestUserProcess());

        //放款中
        if (ProcessInfo_burnin.getInstance().isOrderLoaning()){
            imageIv.setBackgroundResource(R.drawable.img_loan_loaning);
            titleTv.setText(getString(R.string.fragment_loan_loaning_title));
            textTv.setText(getString(R.string.fragment_loan_loaning_text));
            tipsView.setVisibility(View.GONE);
            pageTag_burnin = "LOAN_LOANING_FRAGMENT";
        }else {
            imageIv.setBackgroundResource(R.drawable.img_loan_review);
            titleTv.setText(getString(R.string.fragment_loan_review_title));
            textTv.setText(getString(R.string.fragment_loan_review_text));
            tipsView.setVisibility(View.VISIBLE);
            pageTag_burnin = "LOAN_REVIEWING_FRAGMENT";
        }

        showAccountView.setVisibility(View.VISIBLE);
        accountNameTv.setText("Account");
        accountTextTv.setText("Once the loan is approved, the loan will be transferred to one of your available account.");

        HttpManager_burnin.getInstance().requestLoanApplyDetail();

    }

    @SuppressLint("SetTextI18n")
    public void onLoanApplyDetailResponse(){

        loanAmountTv.setText(Constant_burnin.Money_Unit_Nigeria+" "+ LoanApplyDetailInfo_burnin.getInstance().getAmount());
        loanTermTv.setText(LoanApplyDetailInfo_burnin.getInstance().getDays()+" "+getString(R.string.word_days));
        accountNumTv.setText(LoanApplyDetailInfo_burnin.getInstance().getBankAccount());

    }

}